package com.wwj.code.util.numberUtils;

import java.security.SecureRandom;

/**
 * 订单号生成
 */
public class OrderNumberUtil {

    /**
     * 订单号规则 前缀+时间戳+四位随机数
     *
     * @param prefix
     * @return
     */
    public static String getOrderNumber(String prefix) {
        StringBuffer sb = new StringBuffer();
        sb.append(prefix);
        sb.append(System.currentTimeMillis());
        sb.append((int) ((Math.random() * 9 + 1) * 1000));
        return sb.toString();
    }

    public static String getRandom(Integer length) {
        String result = "";
        SecureRandom rand = new SecureRandom();
        int n = 20;
        if (null != length && length > 0) {
            n = length;
        }
        int randInt = 0;
        for (int i = 0; i < n; i++) {
            randInt = rand.nextInt(10);

            result += randInt;
        }
        return result;
    }

    public static void main(String[] args) {

//        String sss = getOrderNumber("sss");
        System.out.println((Math.random() * 9 + 1) * 1000);
        System.out.println(System.currentTimeMillis());
    }
}
